package com.example.springaidemo.controller.case6;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.zhipuai.ZhiPuAiChatModel;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author stone
 * @date 2025/7/14 11:20
 */
@RestController
@RequestMapping("/case6")
@Slf4j
public class Case6Controller {

    public Case6Controller(ZhiPuAiChatModel chatModel,
                           @Qualifier("mathTools") ToolCallbackProvider toolCallbackProvider) {
        this.chatClient = ChatClient
                .builder(chatModel)
                .defaultToolCallbacks(toolCallbackProvider)
                .build();
    }

    private ChatClient chatClient;

    /**
     * 调用mcp
     */
    @GetMapping("/chat")
    public String chat(@RequestParam("input") String input) {
        // input=一加一等于几
        return this.chatClient.prompt()
                .user(input)
                .call()
                .content();
    }
}
